<?php
// +----------------------------------------------------------------------
// | YFCMF [ WE CAN DO IT MORE SIMPLE]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2018 http://yfcmf.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: rainfer <rainfer520@qq.com>
// +----------------------------------------------------------------------

namespace app\common\model;

use think\Model;

/**
 * 钩子模型
 * @Author: rainfer <rainfer520@qq.com>
 */
class UsersAddress extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'users_address';

    // 追加属性
    protected $append = [
        'province_text',//省名称
        'city_text',//市名称
        'district_text',//县名称
    ];

    //是不是默认地址
    public $default_text=[
        1=>'是',
        2=>'否'
    ];

    public function getProvinceTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['province']) ? $data['province'] : '');
        if ($value==0){return '';}

        $list = Region::get_city_name($value);

        return isset($list) ? $list : '';
    }
    public function getCityTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['city']) ? $data['city'] : '');
        if ($value==0){return '';}
        $list = Region::get_city_name($value);
        return isset($list) ? $list : '';
    }
    public function getDistrictTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['district']) ? $data['district'] : '');
        if ($value==0){return '';}
        $list = Region::get_city_name($value);
        return isset($list) ? $list : '';
    }




    // 设置当前模型的数据库连接
//    protected $connection = 'db_config';

    protected $autoWriteTimestamp = true;




    //关联 follow_id 开发id
//    public function uid()
//    {
//        return $this->belongsTo('Users', 'uid','id');
//    }


//id  int(11) 
//uid   int(11) 用户id
//name  varchar(255) 收货人姓名
//mobile    varchar(20) 手机号
//province  int(11) 
//city  int(11) 
//district  int(11) 
//addressvar    char(255) 详细地址
//defaulttiny   int(4) 默认地址 1是 2否

}
